/*************************************
 * 
 *   89c52 sdcc Timer0 PWM demo
 * 
 * CPU: 89C52
 * FREQ: 11.0592MHz
 * PIN: P37
 * 
 * ***********************************
 */
#include <reg52.h>
#define uint8_t unsigned char
uint8_t cmp = 0;
void Timer0_Init(void){		//200微秒@11.0592MHz
	TMOD &= 0xF0;			//设置定时器模式 0b11110000
	TMOD |= 0x01;			//设置定时器模式 0b00000001
	TL0 = 0x48;				//设置定时初始值
	TH0 = 0xFF;				//设置定时初始值
	TF0 = 0;				//清除TF0标志
	ET0 = 1;				//使能定时器0中断
    EA = 1;                 //使能所有定时器
	TR0 = 1;				//定时器0开始计时
}

void main(void){
    Timer0_Init();
    cmp = 23 ;
    while (1);
}

void Timer0_Isr(void) interrupt (1)
{
    static uint8_t count = 0;
	TL0 = 0x48;				//设置定时初始值
	TH0 = 0xFF;				//设置定时初始值
    if(count<cmp) P37 = 1;
    else P37 = 0;
    count++;
    if(count>=100) count=0;
}
